package main

import (
	"api/internal/config"
	"api/internal/handler"
	"api/internal/svc"
	"flag"
	"fmt"
	"net/http"
	"github.com/speedphp/zeroswagger"
	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/rest"
)

var configFile = flag.String("f", "etc/user-api.yaml", "the config file")

func main() {
	flag.Parse()
	var c config.Config
	conf.MustLoad(*configFile, &c)

	server := rest.MustNewServer(c.RestConf)
	defer server.Stop()

	ctx := svc.NewServiceContext(c)

	// 挂载 swagger ui 路由
	server.AddRoute(zeroswagger.New("/doc").Route())

	// 添加静态文件服务
	server.AddRoute(rest.Route{
		Method: http.MethodGet,
		Path:   "/ws_test.html",
		Handler: func(w http.ResponseWriter, r *http.Request) {
			http.ServeFile(w, r, "ws_test.html")
		},
	})

	handler.RegisterHandlers(server, ctx)

	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
	server.Start()
}
